//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.example.erp.log;

import com.example.erp.domain.GlobalConstant;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;

public class LoggerAppend {
    private StringBuilder builder = new StringBuilder(512);

    public LoggerAppend() {
    }

    public static LoggerAppend create(HttpServletRequest request, LoggerType type) {
        LoggerAppend append = create().append("prefix", type.getName());
        append.append(GlobalConstant.requestURI, request.getRequestURI());
        Map<String, String[]> params = request.getParameterMap();
        Iterator var4 = params.entrySet().iterator();

        while (true) {
            while (var4.hasNext()) {
                Map.Entry<String, String[]> entry = (Map.Entry) var4.next();
                String[] values = (String[]) entry.getValue();
                if (values != null && values.length != 0) {
                    if (values.length == 1) {
                        append.append((String) entry.getKey(), values[0]);
                    } else {
                        append.append((String) entry.getKey(), Arrays.toString(values));
                    }
                } else {
                    append.append((String) entry.getKey(), (String) null);
                }
            }

            return append;
        }
    }

    public static LoggerAppend create() {
        return new LoggerAppend();
    }

    public LoggerAppend append(String key, long value) {
        return this.append(key, String.valueOf(value));
    }

    public LoggerAppend append(String key, String value) {
        this.builder.append(key).append(":").append(value);
        this.builder.append("|");
        return this;
    }

    public String toString() {
        return this.builder.toString();
    }
}
